<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ include file="/views/global/taglibs.jsp"%>
<!DOCTYPE>
<html>
<head>
	<base href="<%=basePath %>">
	<title>${appName} - 定时钟</title>
	<meta http-equiv="pragma" content="no-cache">
	<meta http-equiv="cache-control" content="no-cache">
	<meta http-equiv="expires" content="0">
	
	<%@include file="/views/global/include.jsp" %>
	
	<script type="text/javascript" id="CoralDialog" src="static/javascript/global/CoralDialog/CoralDialog.js"></script>
</head>
<body>
	<%@include file="/views/global/top.jsp" %>
	<div class="main">
		<div class="row">
	  		<div class="col-xs-2">
	  			<%@include file="/views/admin/sider.jsp" %>
	  		</div>
	  		<div class="col-xs-10">
	  			<div class="panel panel-info">
					<div class="panel-heading">
						<div class="panel-title">定时钟列表</div>
					</div>
					<div class="panel-body">
						<div class="row">
							<div class="pull-left">
								<button type="button" class="btn btn-info" onclick="editNode(this, 0)">New...</button>
							</div>
							<div class="pull-right">
								<button type="button" class="btn btn-info" onclick="refreshNode(this)">Refresh</button>
							</div>
						</div>
						<div class="clearfix" style="height:5px;"></div>
						<table class="table table-bordered table-striped">
							<thead>
								<tr>
									<th>Job Name</th>
									<th>Job Class</th>
									<th>CronText</th>
									<th>Depends</th>
									<th></th>
								</tr>
							</thead>
							<tbody>
								<c:forEach var="item" items="${entryList }">
									<tr>
										<td>${item.jobName }</td>
										<td>${item.jobClass }</td>
										<td>${item.cronText }</td>
										<td>${item.dependNames }</td>
										<td>
											<div class="btn-group">
												<button type="button" class="btn btn-info" onclick="executeTask('${item.jobName}', '${item.jobClass }')">Run</button>
												<button type="button" class="btn btn-info" onclick="editNode(this, ${item.id})">Edit</button>
											</div>
										</td>
									</tr>
								</c:forEach>
							</tbody>
						</table>
					</div>
				</div>
	  		</div>
	  	</div>
		<form id="updateForm"></form>
	</div>
	<%@include file="/views/global/AdminScripts.jsp" %>
</body>
<script type="text/javascript">
function editNode(target, objId){
	ShowDialog({width:800, height:650, draggable:true, 
		title: 0== objId?"新增定时钟":"编辑定时钟",href:'dev/scheduler/edit/'+objId,
		close: function(){
			window.location.reload();
		}
	});
	/*
	art.dialog.open('sys/scheduler/edit/'+objId, {
		title: 0== objId?"新增定时钟":"编辑定时钟", close: function(){
			window.location.reload();
		}, lock: true, id: "editSchedulerDialog", top: '15%'
	}, false);
	*/
}

function refreshNode(target){
	$("#updateForm").goAjax({semantic: false,checkLogin: true,
		url: 'dev/scheduler/refreshAll', data:{},
		success: function(jsonData) {
			if(true == jsonData.success){
				$.message("执行成功", {time: 2});
			} else {
				$.error(jsonData.message);
			}
		}
	});
}

function executeTask(jobName, jobClass){
	$("#updateForm").goAjax({semantic: false,checkLogin: true,
		url: 'dev/scheduler/executeTask',
		data:{jobName: jobName, jobClass: jobClass},
		success: function(jsonData) {
			if(true == jsonData.success){
				$.message("执行成功", {time: 2});
			} else {
				$.error(jsonData.message);
			}
		}
	});
}
</script>
</html>
